<?php

#基础函数
include_once('_path.php');

#db
include_once(_CONST_LOCAL_INCLUDE_PATH."database.class.php");
$database = new Database($db_vars);

#通用函数
include_once(_CONST_LOCAL_INCLUDE_PATH."common.php");

session_name('foxid');

$hash = trim($_POST['hash']);
$action = trim($_POST['action']);

$id = trim($_POST['id']); $quote['id'] = string_sql($id);
$s = trim($_POST['s']); $quote['s'] = string_sql($s);
$v = trim($_POST['v']); $quote['v'] = string_sql($v);
$c = trim($_POST['c']); $quote['c'] = string_sql($c);

if ($hash != md5(_CONST_COOKIE_SALT.$id)) {
	exit();
}

echo "<script>";

if ($action == 'check' && $s && $c) {
	
	$quote['no'] = string_sql(pack_volch($v, $c));
	$sql = "SELECT mc.chapter_id, mc.no, ms.name series_name FROM manga_chapters mc ".
		"LEFT JOIN manga_series ms ON ms.series_id = mc.series_id WHERE mc.series_id = ".$quote['s']." AND mc.no = ".$quote['no'];
	$chapter = $database->queryFirst($sql);

	if ($chapter['chapter_id']) {
		?>
		$('state').innerHTML = "Exists &nbsp; <a href=\"../manga/scans.php?chapter_id=<?= $chapter['chapter_id'] ?>\">Go Check</a>";
		$('state').setStyles({'color': '#CC9900', 'white-spacing': 'nowrap', 'padding-left': '18px;', 'display': 'block;', 'background': 'url(<?= _CONST_BACKEND_URL ?>media/error.png) no-repeat center left'});
		<?
	} else {
		?>
		$('state').innerHTML = "Available";
		$('state').setStyles({'color': '#666600', 'white-spacing': 'nowrap', 'padding-left': '18px;', 'display': 'block;', 'background': 'url(<?= _CONST_BACKEND_URL ?>media/tick.png) no-repeat center left'});
		<?
	}	
}

echo "</script>";

?>